package com.client.common;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import android.app.Activity;


public class ValueStack {

	private ValueStack() {

	}
	public static String  ROOT="http://192.168.1.102:8013";
	public static String  IMAGEROOT="http://192.168.1.102:8013/forestry/picture.action?imageName=";
	private static ValueStack mValueStack = null;

	public static ValueStack getInstance() {
		if (mValueStack == null) {
			mValueStack = new ValueStack();
		}
		return mValueStack;
	}
	private HashMap<String, Object> session = new HashMap<String, Object>();
	private HashMap<String, Object> request = new HashMap<String, Object>();
	public Object getSessionValue(String key) {
		if (session.containsKey(key)) {
			return session.get(key);
		}
		return "";

	}
	public void setSessionValue(String key, Object object) {
		if (session.containsKey(key)) {
			session.remove(key);

		}
		session.put(key, object);

	}
	public Object getValue(String key) {
		if (request.containsKey(key)) {
			return request.remove(key);
		}
		return null;

	}
	public static Map<String, Activity> activitys = new HashMap<String, Activity>();

	// // 添加Activity到容器中
	// public void addActivity(Activity activity) {
	// activityList.add(activity);
	// }

	// 遍历所有Activity并finish
	public void exit() {
		Iterator<Entry<String, Activity>> iter = activitys.entrySet()
				.iterator();
		while (iter.hasNext()) {
			Entry<String, Activity> entry = (Entry<String, Activity>) iter
					.next();
			entry.getValue().finish();
		}

	}

	public boolean containsKey(String key) {
		return request.containsKey(key);
	}

	public void setValue(String key, Object object) {
		if (request.containsKey(key)) {
			request.remove(key);

		}
		request.put(key, object);

	}
}
